﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsApplication1
{
    public partial class FormRoot : Form
    {
        string root;
        public FormRoot()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (root == null)
            {
                FolderBrowserDialog folderDlg = new FolderBrowserDialog();
                folderDlg.ShowDialog();
                root=folderDlg.SelectedPath;
                FileStream fs = new FileStream(".\\root.txt", FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(root);                
                sw.Close();
                fs.Close();
                this.textRoot.Text = root;
            }
        }

        private void FormRoot_Load(object sender, EventArgs e)
        {
            if (File.Exists(".\\root.txt"))
            {
                FileStream fs = new FileStream(".\\root.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);
                root = sr.ReadLine();
                this.textRoot.Text = root;
                sr.Close();
                fs.Close();                
            }

        }
    }
}
